package com.you.atlas.biz.place.service.impl;

import java.util.List;

import com.you.atlas.biz.place.service.PlaceViewService;
import com.you.atlas.biz.place.vo.PlaceViewVO;
import com.you.common.ibatis.data.DataList;
import com.you.place.dal.dao.AlbumDAO;
import com.you.place.dal.dao.NoteDAO;
import com.you.place.dal.dao.PhotoDAO;
import com.you.place.dal.dao.PlaceDAO;
import com.you.place.dal.dao.dataobject.NoteDO;
import com.you.place.dal.dao.dataobject.PlaceDO;

public class PlaceViewServiceImpl implements PlaceViewService {

    private PlaceDAO placeDAO;

    private NoteDAO  noteDAO;

    private PhotoDAO photoDAO;

    private AlbumDAO albumDAO;

    public void setPlaceDAO(PlaceDAO placeDAO) {
        this.placeDAO = placeDAO;
    }

    public void setNoteDAO(NoteDAO noteDAO) {
        this.noteDAO = noteDAO;
    }

    public void setPhotoDAO(PhotoDAO photoDAO) {
        this.photoDAO = photoDAO;
    }

    public void setAlbumDAO(AlbumDAO albumDAO) {
        this.albumDAO = albumDAO;
    }

    @Override
    public PlaceViewVO getPlaceViewVO(Long placeId) {
        PlaceViewVO placeViewVO = new PlaceViewVO();
        // set Place
        PlaceDO placeDO = placeDAO.find(placeId);
        placeViewVO.setPlaceDO(placeDO);

        // set Photo
        // List<PhotoDO> photoList = photoDAO.queryTop6(placeId);
        DataList dataList = albumDAO.queryByPlaceId(0, 5, placeId);
        placeViewVO.setPhotoList(dataList.getData());
        placeViewVO.setPhotoCount(dataList.getTotalCount());

        // set Note
        List<NoteDO> noteList = noteDAO.queryTop6(placeId);
        placeViewVO.setNoteList(noteList);
        Long noteCount = noteDAO.count(placeId);
        placeViewVO.setNoteCount(noteCount);

        return placeViewVO;
    }

}
